import clr
import Twitter
from System import *
from System.Net import *
from System.Text import *
from System.Collections import *
from System.Collections.Specialized import *
from System.Windows.Media.Imaging import *

class TwitterXamlPresenter:
	"""I make UI for XAML"""
	def add_to_status_list(self, json):
		for status in json:
			if me.shell.FindName(str(status.id)) == None:
				panel = StackPanel()
				panel.Name = str(status.id)
				img = Image()
				img.Source = BitmapImage(Uri(status.user.profile_image_url.Replace("\\","")))
				img.Width= 50
				img.Height= 50
				tb = TextBlock()
				tb.Text = "%s: %s" % (status.user.name.Replace("\\",""), status.text.Replace("\\",""))
				panel.Children.Add(img)
				panel.Children.Add(tb)
				me.shell.status_list.Children.Add(panel)
		
class TwitterHtmlPresenter:
	""" I make UI for XML"""
	def add_to_status_list(self, json):
		for status in json:
			if(document.GetElementById(str(status.id)) == None):
				document.msg.innerHTML += "<div id=\"%s\" style=\"clear:both;\"><img style=\"float:left\" src=\"%s\" />%s: %s<br/>%s</div>" % \
				(status.id, status.user.profile_image_url.Replace("\\",""), status.user.name.Replace("\\",""), status.text.Replace("\\",""), status.created_at)
		
# methods for the control are not in a class, but made here for delegates. 

def log(msg):
	document.debug.innerHTML = str(msg)

def login_event(sender, eventagrs):
	global twitter 
	twitter = Twitter(me.shell.ux.username.Text.Trim(), me.shell.ux.password.Password.Trim())
	twitter.friends_timeline()
	
def update_status_event(sender, eventargs):
	log("updating status")
	twitter.update(me.shell.status_form.my_status.Text)
	twitter.friends_timeline()
	
#wire up the form
me.shell.ux.update.Click += login_event
me.shell.ux.status_form.update_my_status.Click += update_status_event
		
def help_me():
	print "Use the class to connect to twitter."
	
if __name__ == '__main__':
	help_me()

